module diopmp_top #(parameter ID_IOPMP = 0)
(
input            diopmp_m2s_ahb_hclk          ,
input            diopmp_m2s_ahb_hrst_b        ,

input   [31:0]   diopmp_apb_paddr_i            ,          
input            diopmp_apb_penable_i          ,        
input   [2 :0]   diopmp_apb_pprot_i            ,          
input            diopmp_apb_psel_i             ,           
input   [31:0]   diopmp_apb_pwdata_i           ,         
input            diopmp_apb_pwrite_i           ,  
output  [31:0]   diopmp_apb_check_prdata_o     ,

input    [31:0]  diopmp_apb_prdata_i          ,
output   [31:0]  diopmp_apb_check_paddr_o     ,          
output           diopmp_apb_check_penable_o   ,        
output   [2 :0]  diopmp_apb_check_pprot_o     ,          
output           diopmp_apb_check_psel_o      ,           
output   [31:0]  diopmp_apb_check_pwdata_o    ,         
output           diopmp_apb_check_pwrite_o    ,  

      
input            diopmp_reg_clk_i             ,
input            diopmp_reg_rstn_i            ,
input            diopmp_cfg_en_i              , 
input [7:0]      diopmp_reg_addr_i            ,
input            diopmp_reg_wen_i             ,
input            diopmp_reg_ren_i             ,   
input [31:0]     diopmp_reg_wdata_i           ,  
output[31:0]     diopmp_rddata_o              
 

);


wire [31 : 0]                rg2ck_addrst_cnt  ;
wire [31 : 0]                rg2ck_size_cnt    ;
wire [31 : 0]                rg2ck_rule        ;
wire [9 : 0]                rg2ck_mode        ;

wire                         ctl2ckrg_update_en;
wire                         ctl2ck_rdck_en    ; 
wire                         ctl2rg_wrck_en    ;

wire                         ck2rg_error_flag  ;
wire [15:0]                  ck2rg_error_hit   ;  
wire                         ck2ctl_penable    ;
wire                         ck2ctl_pwrite     ;
wire                         ck2ctl_psel       ;                  
wire                         rg2ctl_cfgen      ;
// wire                         ctl2rg_cfgdone  ;
 
   

diopmp_check u_diopmp_check(
    .diopmpck_clk_i            (diopmp_m2s_ahb_hclk       ),
    .diopmpck_rst_n_i          (diopmp_m2s_ahb_hrst_b     ),
    // from diopmp_reg
    .diopmpck_addrst_cnt_i     (rg2ck_addrst_cnt          ),
    .diopmpck_size_cnt_i       (rg2ck_size_cnt            ),
    .diopmpck_rule_i           (rg2ck_rule                ),
    .diopmpck_mode_i           (rg2ck_mode                ),
    //to diopmp_reg
    .diopmpck_error_o          (ck2rg_error_flag         ),
    .diopmpck_iohit_o          (ck2rg_error_hit           ),
    
   .diopmpck_apb_paddr_i        (diopmp_apb_paddr_i        ),
   .diopmpck_apb_penable_i      (diopmp_apb_penable_i      ),
   .diopmpck_apb_pprot_i        (diopmp_apb_pprot_i        ),
   .diopmpck_apb_psel_i         (diopmp_apb_psel_i         ),
   .diopmpck_apb_pwdata_i       (diopmp_apb_pwdata_i       ),
   .diopmpck_apb_pwrite_i       (diopmp_apb_pwrite_i       ),
   .diopmpck_apb_check_prdata_o (diopmp_apb_check_prdata_o ),

   .diopmpck_apb_prdata_i       (diopmp_apb_prdata_i       ),
   .diopmpck_apb_check_paddr_o  (diopmp_apb_check_paddr_o  ),
   .diopmpck_apb_check_penable_o(diopmp_apb_check_penable_o),
   .diopmpck_apb_check_pprot_o  (diopmp_apb_check_pprot_o  ),
   .diopmpck_apb_check_psel_o   (diopmp_apb_check_psel_o   ),
   .diopmpck_apb_check_pwdata_o (diopmp_apb_check_pwdata_o ),
   .diopmpck_apb_check_pwrite_o (diopmp_apb_check_pwrite_o ),

    //to diopmp_control
    .diopmpck_penable_o          (ck2ctl_penable            ),
    .diopmpck_pwrite_o           (ck2ctl_pwrite             ),
    .diopmpck_psel_o             (ck2ctl_psel               ),
    .diopmpck_check_en_i         (ctl2ckrg_update_en        ),
    .diopmpck_rdck_i             (ctl2ck_rdck_en            ),
    .diopmpck_wrck_i             (ctl2rg_wrck_en            )
);


diopmp_control u_diopmp_control(
    .diopmpctl_clk_i           (diopmp_m2s_ahb_hclk        ),
    .diopmpctl_rst_n_i         (diopmp_m2s_ahb_hrst_b      ),
        
    .diopmpctl_cfgen_i         (rg2ctl_cfgen             ),        

    .diopmpctl_penable_i         (ck2ctl_penable          ),
    .diopmpctl_pwrite_i         (ck2ctl_pwrite            ),
    .diopmpctl_psel_i          (ck2ctl_psel               ),
     
    .diopmpctl_update_en_o     (ctl2ckrg_update_en        ), 
    .diopmpctl_rdck_en_o       (ctl2ck_rdck_en            ),
    .diopmpctl_wrck_en_o       (ctl2rg_wrck_en            )
);



diopmp_reg #(
    .ID                            (ID_IOPMP    )
)
u_diopmp_reg(
    .diopmprg_clk_i       (diopmp_reg_clk_i    ),
    .diopmprg_rst_n_i     (diopmp_reg_rstn_i   ),
    .diopmprg_en_i        (diopmp_cfg_en_i    ),
    .diopmprg_wen_i       (diopmp_reg_wen_i   ),
    .diopmprg_ren_i       (diopmp_reg_ren_i   ),
    .diopmprg_addr_i      (diopmp_reg_addr_i  ),
    .diopmprg_wdat_i      (diopmp_reg_wdata_i),

    .diopmprg_access_ill_i(ck2rg_error_flag     ),
    .diopmprg_hit_i       (ck2rg_error_hit      ),

    .diopmprg_cfgwen_i    (ctl2ckrg_update_en    ),

    .diopmprg_rdat_o      (diopmp_rddata_o      ),
    .diopmprg_cfgen_o     (rg2ctl_cfgen         ),
    .diopmprg_addrst_cnt_o(rg2ck_addrst_cnt     ),
    .diopmprg_size_cnt_o  (rg2ck_size_cnt       ),
    .diopmprg_rule_o      (rg2ck_rule           ),
    .diopmprg_mode_o      (rg2ck_mode           )
); 
endmodule